# -*- coding: utf-8 -*-
# This code written by ChanGOGOGO
"""
callplus主页页面元素
"""
from pages.base_page import BasePage


class HomePage(BasePage):
    def menu(self, menu_name: str = "对话设计"):
        """左侧菜单"""
        element = self.page.locator(
            f"//ul[@role='menubar']//span[@class='menu__item__name' "
            f"and normalize-space()='{menu_name}']"
        )
        return element


if __name__ == "__main__":
    from playwright.sync_api import sync_playwright
    from login_page import LoginPage

    url = "http://172.18.160.72:40080/#/user/login"
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(
            headless=False, channel="msedge", args=["--start-maximized"]
        )
        context = browser.new_context(no_viewport=True)
        t_page = context.new_page()
        t_page.goto(url)
        login_page = LoginPage(t_page)
        login_page.aiforce_id().fill("hongyi@wezhuiyi.com")
        login_page.password().fill("admin@123")
        login_page.login_button().click()
        with t_page.expect_popup() as t_page2:
            login_page.call_business_button("弘毅").click()
        page2 = t_page2.value
        t_page.wait_for_timeout(3000)
        home_page = HomePage(page2)
        home_page.menu("呼出历史").click()
        page2.wait_for_timeout(3000)
